#include <PopupOSAL.hpp>
#include <unistd.h>

using namespace PopupUtils;

Mutex::Mutex() {
  pthread_mutex_init(&mutex, NULL);
}

Mutex::~Mutex() {
  pthread_mutex_destroy(&mutex);
}

int Mutex::lock(bool p_try)
{
  if  (p_try == true) {
    return pthread_mutex_lock(&mutex);
  } else {
    return pthread_mutex_trylock(&mutex);
  }
}

int Mutex::unlock() {
  return pthread_mutex_unlock(&mutex);
}

int PopupThread::start(ThreadRoutine p_routine, void *p_args)
{
  pthread_t _t;
  int _ret = pthread_create(&_t, NULL, p_routine, p_args);
  return _ret;
}

void PopupThread::sleep(int ms)
{
  ::usleep(ms * 1000);
}
